package com.leanin.form.contoller;

import com.leanin.form.model.AdviceDto;
import com.leanin.form.model.request.EduFormDTO;
import com.leanin.form.model.request.FormQueryDTO;
import com.leanin.form.model.response.CommonResponseResult;
import com.leanin.form.model.response.QueryResponseResult;
import com.leanin.form.model.response.ResponseResult;
import com.leanin.form.service.EduFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author CPJ.
 * @date 2019/6/14.
 * @time 15:14.
 */
@RestController
@RequestMapping("/eduForm")
public class EduFormController {


    @Autowired
    private EduFormService eduFormService;

    /**
     * 添加宣教表单
     * @param eduFormDTO
     * @return
     */
    @PostMapping("/addEduForm")
    public CommonResponseResult addEduForm(@RequestBody EduFormDTO eduFormDTO){
        return eduFormService.addEduForm(eduFormDTO);
    }

    /**
     * 修改表单内容
     * @param eduFormDTO
     * @return
     */
    @PutMapping("/updateEduForm")
    public ResponseResult updateEduForm(@RequestBody EduFormDTO eduFormDTO){
        return eduFormService.updateEduForm(eduFormDTO);
    }

    /**
     * 宣教表单条件查询
     * @param formQueryDTO
     * @return
     */
    @PostMapping("/findByParam")
    public QueryResponseResult findByParam(@RequestBody FormQueryDTO formQueryDTO){
        return eduFormService.findByParam(formQueryDTO);
    }

    /**
     * 根据表单id查询表单内容
     * @param formId 表单id
     * @return
     */
    @GetMapping("/findById")
    public CommonResponseResult findById(@RequestParam("formId") Long formId){
        return eduFormService.findById(formId);
    }

    /**
     * 下载表单，修改下载次数
     * @param formId 表单id
     * @return
     */
    @GetMapping("/addDownLoadCount")
    public ResponseResult addDownLoadCount(@RequestParam("formId") Long formId){
        return eduFormService.addDownLoadCount(formId);
    }

    /**
     * 删除表单
     * @param formId
     * @return
     */
    @DeleteMapping("/deleteForm")
    public ResponseResult deleteForm(@RequestParam("formId") Long formId){
        return eduFormService.deleteForm(formId);
    }

    /**
     * 医嘱匹配宣教表单
     * @param advice 医嘱
     * @return
     */
    @GetMapping("findByAdvice")
    public QueryResponseResult findByAdvice(@RequestParam("page") Integer page,@RequestParam("pageSize") Integer pageSize,String advice){
        return eduFormService.findByAdvice(page,pageSize,advice);
    }

    /**
     * 医嘱匹配宣教表单
     * @param adviceDto 医嘱
     * @return
     */
    @PostMapping("findByAdviceList")
    public QueryResponseResult findByAdviceList(@RequestBody AdviceDto adviceDto){
        return eduFormService.findByAdviceList(adviceDto.getPage(),adviceDto.getPageSize(),adviceDto.getAdvices());
    }

}
